package com.github.sbb.sherry.primitives.core;

import com.github.sbb.sherry.common.annotations.NotNull;
import com.github.sbb.sherry.common.base.Preconditions;
import com.github.sbb.sherry.primitives.api.Fact;
import java.util.HashMap;
import java.util.Map;

public class MapFact implements Fact {

  private Map<String, Object> data;

  public MapFact() {
    data = new HashMap<>();
  }

  public MapFact(@NotNull Map<String, Object> data) {
    Preconditions.checkNotNull(data);
    this.data = data;
  }

  @Override
  public int size() {
    return data.size();
  }

  @Override
  public boolean contains(String fieldName) {
    return data.containsKey(fieldName);
  }

  @Override
  public Object get(String fieldName) {
    return data.get(fieldName);
  }

  @Override
  public void set(String fieldName, Object value) {
    data.put(fieldName, value);
  }

  @Override
  public String getString(String fieldName) {
    return (String) data.get(fieldName);
  }

  @Override
  public void setString(String fieldName, String value) {
    data.put(fieldName, value);
  }

  @Override
  public Integer getInteger(String fieldName) {
    return (Integer) data.get(fieldName);
  }

  @Override
  public void setInteger(String fieldName, Integer value) {
    data.put(fieldName, value);
  }
}
